home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Headers / Index / IAIndex.h < prev    next >
Encoding:
Text File  |  1997-09-11  |  5.1 KB  |  163 lines  |  [TEXT/CWIE]

  1. // IAIndex.h
  2. //    Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. #pragma once
  5. #ifndef IAIndex_h
  6. #define IAIndex_h
  7.  
  8. #pragma import on
  9.  
  10. #include "IAAnalysis.h"
  11. #include "IANarrow.h"
  12.  
  13. //#pragma IA_BEGIN_IMPORTS
  14. #include <time.h>
  15. //#pragma IA_END_IMPORTS
  16.  
  17. #pragma IA_BEGIN_EXPORTS
  18.  
  19. struct IAIndexTypes {
  20.         IAIndexTypes();
  21.         IAIndexTypes(uint32 storageType, uint32 corpusType, uint32 analysisType, uint32 indexType);
  22.  
  23.     // Returns true iff two IAIndexTypes are equal.        
  24.     bool            Equal(IAIndexTypes* other);
  25.     void             Store(IAOutputBlock* output) const;
  26.     void            Restore(IAInputBlock* input);
  27.         
  28.     uint32    storageType;
  29.     uint32    corpusType;
  30.     uint32    analysisType;
  31.     uint32    indexType;
  32.     uint32    osSetType;
  33. private:
  34.     void*    operator new(size_t size);        // stack allocate only
  35. };
  36.  
  37. class IAIndex : public IAObject {
  38. public:    // constructors
  39.         IAIndex(IAStorage* s, IACorpus* c, IAAnalysis* a, uint32 t, IABlockID r = NULL);
  40.  
  41.     virtual        ~IAIndex();                    // deletes corpus, analysis & mutex
  42.  
  43.     // Initializes a new emtpy index in a new empty storage.
  44.     virtual void            Initialize();
  45.     // Opens an existing index.
  46.     // By default, Calls Open() on the storage, corpus and analysis.
  47.     virtual void            Open();
  48.  
  49.     // Uses the corpus iterator to add new documents and delete expired documents.
  50.     // Simple applications should be able to maintain an index with just this method,
  51.     // Complex applications will need the more fine-grained control of the subsequent methods.
  52.     virtual void            Update();
  53.  
  54.     // Adds a document to the index.
  55.     virtual void            AddDoc(IADoc* doc) = 0;
  56.     // Updates the indexes references to an (unchanged) document.
  57.     virtual void            RenameDoc(const IADoc* oldName, const IADoc* newName) = 0;
  58.     // Removes a no-longer extant document (i.e., won’t call Text(id)).
  59.     virtual void            DeleteDoc(const IADoc* doc) = 0;
  60.     // Flushes all changes.  Call just before storage->Commit().
  61.     virtual void            Flush();
  62.     // Returns the time of the last call to Flush().
  63.     time_t                    UpdateTime() { return updateTime; }
  64.     // Attempts to compact the index.
  65.     virtual void            Compact();
  66.  
  67.     // Merges an array of indices into an index.
  68.     // The index, corpus and analysis classes must be the same for all indices.
  69.     // The indices must be disjoint -- no documents may be indexed in more than one index.
  70.     virtual void            Merge(IAIndex** indices, uint32 indexCount) = 0;
  71.  
  72.     // Returns true if a document is indexed.
  73.     virtual bool            IsDocIndexed(const IADoc* doc) = 0;
  74.  
  75.     // Returns the total number of documents indexed.
  76.     virtual uint32            GetDocCount() = 0;
  77.  
  78.     // Returns an iterator over all the documents indexed.
  79.     virtual IADocIterator*    GetDocIterator() = 0;
  80.     virtual IADocIterator*    GetDocIterator(const IADoc* start) = 0;
  81.  
  82.  
  83.     // Accesses the types of an index.  May be called at any time.
  84.     void                    GetIndexTypes(IAIndexTypes* types);
  85.     
  86.     IADefineNarrowMethods(IAIndex, IAIndex);                // support for IANarrow
  87.     
  88.     virtual IAAnalysis*        GetQueryAnalysis() const;
  89.     void            SetPreferredAnalysis(const IAAnalysis* analysis = NULL);
  90.     IAAnalysis*        GetPreferredAnalysis() const;
  91.     
  92.     IAStorage*                GetStorage() const {return storage;}
  93.     IACorpus*                GetCorpus() const {return corpus;}
  94.     IAAnalysis*                GetAnalysis() const {return analysis;}
  95.     uint32                    GetIndexType() const {return indexType;}
  96.     IABlockID                GetIndexRoot() const {return indexRoot;}
  97.     
  98.     void                    SetMaxDocumentSize(uint32 s = 2000) {fMaxDocSize = s;}
  99.     uint32                    GetMaxDocumentSize() const {return fMaxDocSize;}
  100.  
  101. protected:
  102.     // Root is stored by Initialize()--before Initializing() is called--and by Flush().
  103.     // The root is restored by Open().
  104.     // Subclasses can add data to the root block by defining these.
  105.     virtual IABlockSize        RootSize();
  106.     virtual void            StoreRoot(IAOutputBlock* output);
  107.     virtual void            RestoreRoot(IAInputBlock* input);
  108.     // Subclasses can add subsequent initializations by defining this.
  109.     // The base implementation initializes the corpus and analysis.
  110.     virtual void            Initializing();
  111.  
  112.     // Stored in the root block:
  113.     time_t                    updateTime;
  114.     IABlockID                corpusRoot;
  115.     IABlockID                analysisRoot;
  116.  
  117.     bool                    isOpen;
  118.     IAMutex*                mutex;
  119.     
  120.     // default constructor etc. so that this can be a virtual base class
  121.                 IAIndex();
  122.     void        Constructing(IAStorage* s, IACorpus* c, IAAnalysis* a, uint32 t, IABlockID r);
  123.     bool        isConstructed;
  124. private:
  125.     IAAnalysis*            fPreferedAnalysis;  // if set then is used for quey analysis 
  126.     
  127.     IAIndex(IAIndex&);            // don't define a copy constructor
  128.     
  129.     IAStorage*                storage;
  130.     IACorpus*                corpus;
  131.     IAAnalysis*                analysis;
  132.     
  133.     uint32                    indexType;
  134.     IABlockID                indexRoot;
  135.     
  136.     // The maximum number of tokens indexed per doc.
  137.     // Documents longer than this are currently truncated.
  138.     uint32                fMaxDocSize;
  139.  
  140.  
  141. };
  142.  
  143. void IAReadIndexTypes(IAStorage* storage, IABlockID indexRoot, IAIndexTypes* types);
  144.  
  145. IAExceptionCode                    IndexInvalid = 'VIIV';
  146. IAExceptionCode                    IndexNotInitialized = 'VINI';
  147. IAExceptionCode                    IndexNotOpen = 'VINO';
  148. IAExceptionCode                    IndexAlreadyOpen = 'VIAO';
  149. IAExceptionCode                    IndexDocAlreadyIndexed = 'VIAI';
  150. IAExceptionCode                    IndexDocNotIndexed = 'VIDN';
  151.  
  152. inline IAAnalysis* IAIndex::GetPreferredAnalysis() const
  153. {
  154.     return fPreferedAnalysis;
  155. }
  156.  
  157.  
  158. #pragma IA_END_EXPORTS
  159.  
  160. #pragma import reset
  161.  
  162. #endif
  163.